# Maintainer: Balló György <ballogyor+arch at gmail dot com>
# Contributor: Tom Richards <tom@tomrichards.net>

pkgname=gnome-games
pkgver=40.0
pkgrel=3
pkgdesc='Simple game launcher for GNOME'
arch=('loong64' 'x86_64')
url='https://wiki.gnome.org/Apps/Games'
license=('GPL3')
groups=('gnome-extra')
depends=('grilo' 'libarchive' 'libhandy' 'libmanette' 'retro-gtk' 'tracker3')
makedepends=('appstream-glib' 'meson' 'vala')
optdepends=('libretro-beetle-pce-fast: Support for TurboGrafx-16 and TurboGrafx-CD games'
            'libretro-beetle-psx: Support for PlayStation games'
            'libretro-blastem: Support for Sega Genesis games'
            'libretro-citra: Support for Nintendo 3DS games'
            'libretro-flycast: Support for Dreamcast games'
            'libretro-gambatte: Support for Game Boy and Game Boy Color games'
            'libretro-mgba: Support for Game Boy Advance games'
            'libretro-nestopia: Support for Nintendo Entertainment System and Famicom Disk System games'
            'libretro-parallel-n64: Support for Nintendo 64 games'
            'libretro-picodrive: Support for Master System, Genesis 32X, Sega CD, Sega CD 32X, Sega Genesis and Sega Pico games')
#            'libretro-beetle-ngp: Support for Neo Geo Pocket and Neo Geo Pocket Color games'
#            'libretro-beetle-vb: Support for Virtual Boy games'
#            'libretro-beetle-wswan: Support for WonderSwan and WonderSwan Color games'
#            'libretro-bsnes-mercury-balanced: Support for Super Nintendo Entertainment System games'
#            'libretro-desmume2015: Support for Nintendo DS games'
#            'libretro-gearsystem: Support for Game Gear, Master System and SG-1000 games'
#            'libretro-handy: Support for Atari Lynx games' 
#            'libretro-prosystem: Support for Atari 7800 games'
#            'libretro-stella2014: Support for Atari 2600 games'
source=("https://download.gnome.org/sources/$pkgname/${pkgver%.*}/$pkgname-$pkgver.tar.xz"
        'tracker3.patch'
        'meson-0.60.patch')
sha256sums=('32cd413f89292a74b0a84a5a30d0f4878ce42caea36374b1fb4dce3b4f6adf0f'
            '6eaa476f7de1b17848ea64ce99b583a431c3cce6b48d49f034ac2d611a1bdb27'
            'dc55d441d90c70f1767ec84390b95364a599397ce3af98d4d1b4f5368a4eb89c')

prepare() {
  cd $pkgname-$pkgver
  # Port to Tracker 3
  patch -Np1 -i ../tracker3.patch

  # Fix build with meson 0.60 (Alpine)
  patch -p1 -i ../meson-0.60.patch

  # Replace pcsx_rearmed with mednafen_psx
  mv flatpak/libretro-cores/{pcsx_rearmed,mednafen_psx}.libretro
  sed -i 's/^Name=.*/Name=Beetle PSX/
          s/^Module=.*/Module=mednafen_psx_libretro.so/
          s/^Authors=.*/Authors=Mednafen Team;/' \
    flatpak/libretro-cores/mednafen_psx.libretro
}

build() {
  arch-meson $pkgname-$pkgver build
  meson compile -C build
}

check() {
  meson test -C build --print-errorlogs
}

package() {
  DESTDIR="$pkgdir" meson install -C build

  # Install *.libretro files
  install -dm755 "$pkgdir/usr/lib/libretro/"
  install -Dm644 $pkgname-$pkgver/flatpak/libretro-cores/*.libretro "$pkgdir/usr/lib/libretro/"
}
